package 题目集.递推;

/**
 * https://leetcode.cn/problems/minimum-operations-to-make-binary-array-elements-equal-to-one-ii/?envType=daily-question&envId=2024-10-19
 */
public class ch03_使二进制数组全部等于1的最少操作次数_2 {
    public int minOperations(int[] nums) {
        int cnt = 0;
        int pre = 0;
        for (int i = 0; i < nums.length; i++) {
            if ((nums[i] ^ pre) == 0) {
                cnt++;
                pre ^= 1;
            }
        }
        return cnt;
    }
}
